<template>
    <vol-box
      :lazy="true"
      v-model="model"
      title="选择服务清单"
      :height="400"
      :width="1200"
      :padding="5"
      :onModelClose="onModelClose"
    >
      <div>
        <Operations_qd ref="Operations_qd"></Operations_qd>
      </div>
      <template #footer>
        <div>
          <el-button type="primary" size="small" @click="onSelect"
            >确认</el-button
          >
        </div>
      </template>
    </vol-box>
  </template>
  <script>
  import VolBox from "@/components/basic/VolBox.vue";
  import Operations_qd from "@/views/operationsinfo/operations_qd/q_operations_qd.vue";
  //这里使用的vue2语法，也可以写成vue3语法
  export default {
    components: {
      "vol-box": VolBox,
      Operations_qd,
    },
    data() {
      return {
        model: false,
      };
    },
    methods: {
      async onModelClose() {
        await this.$refs.Operations_qd.$refs.grid.search();
      },
      open(Site) {
        this.model = true;
        let setIntervalTiem = setInterval(() => {
          if (this.$refs.Operations_qd) {
            // console.log("this.$refs.operationsContract.$refs.grid",this.$refs.Operations_qd.$refs.grid.$refs.table.paginations)//paginations
            this.$refs.Operations_qd.$refs.grid.$refs.table.paginations.size=120
            this.$refs.Operations_qd.$refs.grid.$refs.table.paginations.rows=120
            this.$refs.Operations_qd.$refs.grid.$refs.table.paginations.sizes=[120]
            clearInterval(setIntervalTiem);
            this.$refs.Operations_qd.searchFormFields.合同编码 = Site;
            this.$refs.Operations_qd.searchFormOptions.forEach(item => {
                item.forEach(x => {
                  if(x.field == "合同编码"){
                    x.disabled = true
                  }
                })
            })
            this.$refs.Operations_qd.$refs.grid.search();
          }
        }, 100);
      },
  
      onSelect() {
        let rowObj = this.$refs.Operations_qd.$refs.grid.getSelectRows();
        if (!rowObj.length) {
            this.base.ElMessageFn("请至少选择一条数据");
          return (this.model = true);
        }
        // let AuditStatusSome = rowObj.some((item) => item.AuditStatus != 1);
        // if (AuditStatusSome) {
        //     this.base.ElMessageFn("请勿选择审核未通过单据");
        //   return;
        // }
        this.$emit("parentCall", ($parent) => {
          try {
            //处理明细表已含有相同数据
            let arr;
              arr = rowObj.map((item) => {
                return {
                  Code: item.运维内容编码,
                  Name: item.运维内容,
                  Operations_date: item.应运维日期,
                };
              });
            $parent.$refs.detail.rowData.unshift(...arr);
          } catch (error) {
            console.log(error);
          }
        });
        this.onModelClose();
        return (this.model = false);
      },
    },
  };
  </script>